package main

import (
	"encoding/json"
	"fmt"
)

func main() {
	marshalIndentTest()

	/*
	apiUrl := "http://127.0.0.1:8081/json"
	// data用于构建url的参数,url.Values{}底层是一个map
	data := url.Values{}
	//data.Set("name", "小王子")
	data.Set("age", "18")
	u, err := url.ParseRequestURI(apiUrl) //把字符串转化为url对象
	if err != nil {
		fmt.Printf("parse url requestUrl failed, err:%v\n", err)
	}
	fmt.Println("ParseRequestURI u:", u)
	*/
}

func marshalIndentTest()  {
	c := make(map[string]interface{})
	c["name"] = "Gopher"
	c["title"] = "programmer"
	c["contact"] = map[string]interface{}{
		"home": "415.332.23",
		"cell": "415.568.25",
	}
	//data, err := json.MarshalIndent(c, "", "    ")
	data, err:= json.Marshal(c)
	if err != nil {
		fmt.Println("错误为：",err)
		//log.Println("error:", err)
		return
	}